package gov.kqqzyyy.monkey.orderpad.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.Collections;
import java.util.List;

import gov.kqqzyyy.monkey.orderpad.R;
import gov.kqqzyyy.monkey.orderpad.object.Patient_JRHC;

/**
 * Created by Monkey on 2018/3/13.
 * 今日换床病人
 */

public class PatientJRHCAdapter extends BaseAdapter {

    private final LayoutInflater inflater;
    private List<Patient_JRHC> list;

    public PatientJRHCAdapter(Context context) {
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<Patient_JRHC> list) {
        this.list = list;
        Collections.sort(list, (t0, t1) -> t0.getHhch().compareTo(t1.getHhch()));
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (list != null && position < list.size()) {
            return list.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_patient_jrhc, parent, false);
            holder.brxm_tv = convertView.findViewById(R.id.item_jrhc_brxm);
            holder.hqcw_tv = convertView.findViewById(R.id.item_jrhc_hqcw);
            holder.hhcw_tv = convertView.findViewById(R.id.item_jrhc_hhcw);
            holder.hqbq_tv = convertView.findViewById(R.id.item_jrhc_hqbq);
            holder.hhbq_tv = convertView.findViewById(R.id.item_jrhc_hhbq);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Patient_JRHC patientJrhc = list.get(position);
        if (patientJrhc != null) {
            holder.brxm_tv.setText(patientJrhc.getBrxm());
            holder.hqcw_tv.setText(patientJrhc.getHqch());
            holder.hhcw_tv.setText(patientJrhc.getHhch());
            holder.hqbq_tv.setText(patientJrhc.getHqbqMc());
            holder.hhbq_tv.setText(patientJrhc.getHhbqMc());
        }
        return convertView;
    }

    private static class ViewHolder {
        TextView brxm_tv;
        TextView hqcw_tv;
        TextView hhcw_tv;
        TextView hqbq_tv;
        TextView hhbq_tv;
    }
}
